home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Finder Dungeon / source code / MoreFiles 1.4.6 / C Headers / DirectoryCopy.h next >
Encoding:
C/C++ Source or Header  |  1997-06-28  |  20.6 KB  |  494 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    DirectoryCopy: A robust, general purpose directory copy routine.
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support Emeritus
  7. **
  8. **    File:        DirectoryCopy.h
  9. **
  10. **    Copyright © 1992-1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #ifndef __DIRECTORYCOPY__
  23. #define __DIRECTORYCOPY__
  24.  
  25. #include <Types.h>
  26. #include <Files.h>
  27.  
  28. #include "Optimization.h"
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. /*****************************************************************************/
  35.  
  36. enum
  37. {
  38.     getNextItemOp            = 1,    /* couldn't access items in this directory - no access privileges */
  39.     copyDirCommentOp        = 2,    /* couldn't copy directory's Finder comment */
  40.     copyDirAccessPrivsOp    = 3,    /* couldn't copy directory's AFP access privileges */
  41.     copyDirFMAttributesOp    = 4,    /* couldn't copy directory's File Manager attributes */
  42.     dirCreateOp                = 5,    /* couldn't create destination directory */
  43.     fileCopyOp                = 6        /* couldn't copy file */
  44. };
  45.  
  46. /*****************************************************************************/
  47.  
  48. typedef    pascal    Boolean    (*CopyErrProcPtr) (OSErr error,
  49.                                            short failedOperation,
  50.                                            short srcVRefNum,
  51.                                            long srcDirID,
  52.                                            ConstStr255Param srcName,
  53.                                            short dstVRefNum,
  54.                                            long dstDirID,
  55.                                            ConstStr255Param dstName);
  56. /*    ¶ Prototype for the CopyErrProc function DirectoryCopy calls.
  57.     This is the prototype for the CopyErrProc function DirectoryCopy
  58.     calls if an error condition is detected sometime during the copy.  If
  59.     CopyErrProc returns false, then DirectoryCopy attempts to continue with
  60.     the directory copy operation.  If CopyErrProc returns true, then
  61.     DirectoryCopy stops the directory copy operation.
  62.  
  63.     error            input:    The error result code that caused CopyErrProc to
  64.                             be called.
  65.     failedOperation    input:    The operation that returned an error to
  66.                             DirectoryCopy.
  67.     srcVRefNum        input:    Source volume specification.
  68.     srcDirID        input:    Source directory ID.
  69.     srcName            input:    Source file or directory name, or nil if
  70.                             srcDirID specifies the directory.
  71.     dstVRefNum        input:    Destination volume specification.
  72.     dstDirID        input:    Destination directory ID.
  73.     dstName            input:    Destination file or directory name, or nil if
  74.                             dstDirID specifies the directory.
  75.  
  76.     __________
  77.     
  78.     Also see:    FilteredDirectoryCopy, FSpFilteredDirectoryCopy, DirectoryCopy, FSpDirectoryCopy
  79. */
  80.  
  81. #define CallCopyErrProc(userRoutine, error, failedOperation, srcVRefNum, srcDirID, srcName, dstVRefNum, dstDirID, dstName) \
  82.         (*(userRoutine))((error), (failedOperation), (srcVRefNum), (srcDirID), (srcName), (dstVRefNum), (dstDirID), (dstName))
  83.  
  84. /*****************************************************************************/
  85.  
  86. typedef    pascal    Boolean    (*CopyFilterProcPtr) (const CInfoPBRec * const cpbPtr);
  87.  
  88. /*    ¶ Prototype for the CopyFilterProc function.
  89.     This is the prototype for the CopyFilterProc function called by
  90.     FilteredDirectoryCopy and GetLevelSize. If true is returned,
  91.     the file/folder is included in the copy, otherwise it is excluded.
  92.     
  93.     pb    input:    Points to the CInfoPBRec for the item under consideration.
  94.  
  95.     __________
  96.     
  97.     Also see:    FilteredDirectoryCopy, FSpFilteredDirectoryCopy
  98. */
  99.  
  100. #define CallCopyFilterProc(userRoutine, cpbPtr) (*(userRoutine))((cpbPtr))
  101.  
  102. /*****************************************************************************/
  103.  
  104. pascal    OSErr    FilteredDirectoryCopy(short srcVRefNum,
  105.                                       long srcDirID,
  106.                                       ConstStr255Param srcName,
  107.                                       short dstVRefNum,
  108.                                       long dstDirID,
  109.                                       ConstStr255Param dstName,
  110.                                       void *copyBufferPtr,
  111.                                       long copyBufferSize,
  112.                                       Boolean preflight,
  113.                                       CopyErrProcPtr copyErrHandler,
  114.                                       CopyFilterProcPtr copyFilterProc);
  115. /*    ¶ Make a copy of a directory structure in a new location with item filtering.
  116.     The FilteredDirectoryCopy function makes a copy of a directory
  117.     structure in a new location. If copyBufferPtr <> NIL, it points to
  118.     a buffer of copyBufferSize that is used to copy files data. The
  119.     larger the supplied buffer, the faster the copy. If
  120.     copyBufferPtr = NIL, then this routine allocates a buffer in the
  121.     application heap. If you pass a copy buffer to this routine, make
  122.     its size a multiple of 512 ($200) bytes for optimum performance.
  123.     
  124.     The optional copyFilterProc parameter lets a routine you define
  125.     decide what files or directories are copied to the destination.
  126.     
  127.     FilteredDirectoryCopy normally creates a new directory *in* the
  128.     specified destination directory and copies the source directory's
  129.     content into the new directory. However, if root parent directory
  130.     (fsRtParID) is passed as the dstDirID parameter and NULL is
  131.     passed as the dstName parameter, DirectoryCopy renames the
  132.     destination volume to the source directory's name (truncating
  133.     if the name is longer than 27 characters) and copies the source
  134.     directory's content into the destination volume's root directory.
  135.     This special case is supported by FilteredDirectoryCopy, but
  136.     not by FSpFilteredDirectoryCopy since with FSpFilteredDirectoryCopy,
  137.     the dstName parameter can not be NULL.
  138.     
  139.     srcVRefNum        input:    Source volume specification.
  140.     srcDirID        input:    Source directory ID.
  141.     srcName            input:    Source directory name, or nil if
  142.                             srcDirID specifies the directory.
  143.     dstVRefNum        input:    Destination volume specification.
  144.     dstDirID        input:    Destination directory ID.
  145.     dstName            input:    Destination directory name, or nil if
  146.                             dstDirID specifies the directory.
  147.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  148.                             is used the i/o buffer for the copy or
  149.                             nil if you want DirectoryCopy to allocate its
  150.                             own buffer in the application heap.
  151.     copyBufferSize    input:    The size of the buffer pointed to
  152.                             by copyBufferPtr.
  153.     preflight        input:    If true, DirectoryCopy makes sure there are
  154.                             enough allocation blocks on the destination
  155.                             volume to hold the directory's files before
  156.                             starting the copy.
  157.     copyErrHandler    input:    A pointer to the routine you want called if an
  158.                             error condition is detected during the copy, or
  159.                             nil if you don't want to handle error conditions.
  160.                             If you don't handle error conditions, the first
  161.                             error will cause the copy to quit and
  162.                             DirectoryCopy will return the error.
  163.                             Error handling is recommended...
  164.     copyFilterProc    input:    A pointer to the filter routine you want called
  165.                             for each item in the source directory, or NULL
  166.                             if you don't want to filter.
  167.     
  168.     Result Codes
  169.         noErr                0        No error
  170.         readErr                –19        Driver does not respond to read requests
  171.         writErr                –20        Driver does not respond to write requests
  172.         badUnitErr            –21        Driver reference number does not
  173.                                     match unit table
  174.         unitEmptyErr        –22        Driver reference number specifies a
  175.                                     nil handle in unit table
  176.         abortErr            –27        Request aborted by KillIO
  177.         notOpenErr            –28        Driver not open
  178.         dskFulErr            -34        Destination volume is full
  179.         nsvErr                -35        No such volume
  180.         ioErr                -36        I/O error
  181.         bdNamErr            -37        Bad filename
  182.         tmfoErr                -42        Too many files open
  183.         fnfErr                -43        Source file not found, or destination
  184.                                     directory does not exist
  185.         wPrErr                -44        Volume locked by hardware
  186.         fLckdErr            -45        File is locked
  187.         vLckdErr             -46        Destination volume is read-only
  188.         fBsyErr                 -47        The source or destination file could
  189.                                     not be opened with the correct access
  190.                                     modes
  191.         dupFNErr            -48        Destination file already exists
  192.         opWrErr                -49        File already open for writing
  193.         paramErr            -50        No default volume or function not
  194.                                     supported by volume
  195.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  196.         memFullErr            -108    Copy buffer could not be allocated
  197.         dirNFErr            -120    Directory not found or incomplete pathname
  198.         wrgVolTypErr        -123    Function not supported by volume
  199.         afpAccessDenied        -5000    User does not have the correct access
  200.         afpDenyConflict        -5006    The source or destination file could
  201.                                     not be opened with the correct access
  202.                                     modes
  203.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  204.                                     or incomplete pathname
  205.     
  206.     __________
  207.     
  208.     Also see:    CopyErrProcPtr, CopyFilterProcPtr, FSpFilteredDirectoryCopy,
  209.                 DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
  210. */
  211.  
  212. /*****************************************************************************/
  213.  
  214. pascal    OSErr    FSpFilteredDirectoryCopy(const FSSpec *srcSpec,
  215.                                          const FSSpec *dstSpec,
  216.                                          void *copyBufferPtr,
  217.                                          long copyBufferSize,
  218.                                          Boolean preflight,
  219.                                          CopyErrProcPtr copyErrHandler,
  220.                                          CopyFilterProcPtr copyFilterProc);
  221. /*    ¶ Make a copy of a directory structure in a new location with item filtering.
  222.     The FSpFilteredDirectoryCopy function makes a copy of a directory
  223.     structure in a new location. If copyBufferPtr <> NIL, it points to
  224.     a buffer of copyBufferSize that is used to copy files data. The
  225.     larger the supplied buffer, the faster the copy. If
  226.     copyBufferPtr = NIL, then this routine allocates a buffer in the
  227.     application heap. If you pass a copy buffer to this routine, make
  228.     its size a multiple of 512 ($200) bytes for optimum performance.
  229.     
  230.     The optional copyFilterProc parameter lets a routine you define
  231.     decide what files or directories are copied to the destination.
  232.     
  233.     srcSpec            input:    An FSSpec record specifying the directory to copy.
  234.     dstSpec            input:    An FSSpec record specifying destination directory
  235.                             of the copy.
  236.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  237.                             is used the i/o buffer for the copy or
  238.                             nil if you want DirectoryCopy to allocate its
  239.                             own buffer in the application heap.
  240.     copyBufferSize    input:    The size of the buffer pointed to
  241.                             by copyBufferPtr.
  242.     preflight        input:    If true, FSpDirectoryCopy makes sure there are
  243.                             enough allocation blocks on the destination
  244.                             volume to hold the directory's files before
  245.                             starting the copy.
  246.     copyErrHandler    input:    A pointer to the routine you want called if an
  247.                             error condition is detected during the copy, or
  248.                             nil if you don't want to handle error conditions.
  249.                             If you don't handle error conditions, the first
  250.                             error will cause the copy to quit and
  251.                             DirectoryCopy will return the error.
  252.                             Error handling is recommended...
  253.     copyFilterProc    input:    A pointer to the filter routine you want called
  254.                             for each item in the source directory, or NULL
  255.                             if you don't want to filter.
  256.     
  257.     Result Codes
  258.         noErr                0        No error
  259.         readErr                –19        Driver does not respond to read requests
  260.         writErr                –20        Driver does not respond to write requests
  261.         badUnitErr            –21        Driver reference number does not
  262.                                     match unit table
  263.         unitEmptyErr        –22        Driver reference number specifies a
  264.                                     nil handle in unit table
  265.         abortErr            –27        Request aborted by KillIO
  266.         notOpenErr            –28        Driver not open
  267.         dskFulErr            -34        Destination volume is full
  268.         nsvErr                -35        No such volume
  269.         ioErr                -36        I/O error
  270.         bdNamErr            -37        Bad filename
  271.         tmfoErr                -42        Too many files open
  272.         fnfErr                -43        Source file not found, or destination
  273.                                     directory does not exist
  274.         wPrErr                -44        Volume locked by hardware
  275.         fLckdErr            -45        File is locked
  276.         vLckdErr             -46        Destination volume is read-only
  277.         fBsyErr                 -47        The source or destination file could
  278.                                     not be opened with the correct access
  279.                                     modes
  280.         dupFNErr            -48        Destination file already exists
  281.         opWrErr                -49        File already open for writing
  282.         paramErr            -50        No default volume or function not
  283.                                     supported by volume
  284.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  285.         memFullErr            -108    Copy buffer could not be allocated
  286.         dirNFErr            -120    Directory not found or incomplete pathname
  287.         wrgVolTypErr        -123    Function not supported by volume
  288.         afpAccessDenied        -5000    User does not have the correct access
  289.         afpDenyConflict        -5006    The source or destination file could
  290.                                     not be opened with the correct access
  291.                                     modes
  292.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  293.                                     or incomplete pathname
  294.     
  295.     __________
  296.     
  297.     Also see:    CopyErrProcPtr, CopyFilterProcPtr, FilteredDirectoryCopy,
  298.                 DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
  299. */
  300.  
  301. /*****************************************************************************/
  302.  
  303. pascal    OSErr    DirectoryCopy(short srcVRefNum,
  304.                               long srcDirID,
  305.                               ConstStr255Param srcName,
  306.                               short dstVRefNum,
  307.                               long dstDirID,
  308.                               ConstStr255Param dstName,
  309.                               void *copyBufferPtr,
  310.                               long copyBufferSize,
  311.                               Boolean preflight,
  312.                               CopyErrProcPtr copyErrHandler);
  313. /*    ¶ Make a copy of a directory structure in a new location.
  314.     The DirectoryCopy function makes a copy of a directory structure in a
  315.     new location. If copyBufferPtr <> NIL, it points to a buffer of
  316.     copyBufferSize that is used to copy files data.  The larger the
  317.     supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then this
  318.     routine allocates a buffer in the application heap. If you pass a
  319.     copy buffer to this routine, make its size a multiple of 512
  320.     ($200) bytes for optimum performance.
  321.     
  322.     DirectoryCopy normally creates a new directory *in* the specified
  323.     destination directory and copies the source directory's content into
  324.     the new directory. However, if root parent directory (fsRtParID)
  325.     is passed as the dstDirID parameter and NULL is passed as the
  326.     dstName parameter, DirectoryCopy renames the destination volume to
  327.     the source directory's name (truncating if the name is longer than
  328.     27 characters) and copies the source directory's content into the
  329.     destination volume's root directory. This special case is supported
  330.     by DirectoryCopy, but not by FSpDirectoryCopy since with
  331.     FSpDirectoryCopy, the dstName parameter can not be NULL.
  332.     
  333.     srcVRefNum        input:    Source volume specification.
  334.     srcDirID        input:    Source directory ID.
  335.     srcName            input:    Source directory name, or nil if
  336.                             srcDirID specifies the directory.
  337.     dstVRefNum        input:    Destination volume specification.
  338.     dstDirID        input:    Destination directory ID.
  339.     dstName            input:    Destination directory name, or nil if
  340.                             dstDirID specifies the directory.
  341.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  342.                             is used the i/o buffer for the copy or
  343.                             nil if you want DirectoryCopy to allocate its
  344.                             own buffer in the application heap.
  345.     copyBufferSize    input:    The size of the buffer pointed to
  346.                             by copyBufferPtr.
  347.     preflight        input:    If true, DirectoryCopy makes sure there are
  348.                             enough allocation blocks on the destination
  349.                             volume to hold the directory's files before
  350.                             starting the copy.
  351.     copyErrHandler    input:    A pointer to the routine you want called if an
  352.                             error condition is detected during the copy, or
  353.                             nil if you don't want to handle error conditions.
  354.                             If you don't handle error conditions, the first
  355.                             error will cause the copy to quit and
  356.                             DirectoryCopy will return the error.
  357.                             Error handling is recommended...
  358.     
  359.     Result Codes
  360.         noErr                0        No error
  361.         readErr                –19        Driver does not respond to read requests
  362.         writErr                –20        Driver does not respond to write requests
  363.         badUnitErr            –21        Driver reference number does not
  364.                                     match unit table
  365.         unitEmptyErr        –22        Driver reference number specifies a
  366.                                     nil handle in unit table
  367.         abortErr            –27        Request aborted by KillIO
  368.         notOpenErr            –28        Driver not open
  369.         dskFulErr            -34        Destination volume is full
  370.         nsvErr                -35        No such volume
  371.         ioErr                -36        I/O error
  372.         bdNamErr            -37        Bad filename
  373.         tmfoErr                -42        Too many files open
  374.         fnfErr                -43        Source file not found, or destination
  375.                                     directory does not exist
  376.         wPrErr                -44        Volume locked by hardware
  377.         fLckdErr            -45        File is locked
  378.         vLckdErr             -46        Destination volume is read-only
  379.         fBsyErr                 -47        The source or destination file could
  380.                                     not be opened with the correct access
  381.                                     modes
  382.         dupFNErr            -48        Destination file already exists
  383.         opWrErr                -49        File already open for writing
  384.         paramErr            -50        No default volume or function not
  385.                                     supported by volume
  386.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  387.         memFullErr            -108    Copy buffer could not be allocated
  388.         dirNFErr            -120    Directory not found or incomplete pathname
  389.         wrgVolTypErr        -123    Function not supported by volume
  390.         afpAccessDenied        -5000    User does not have the correct access
  391.         afpDenyConflict        -5006    The source or destination file could
  392.                                     not be opened with the correct access
  393.                                     modes
  394.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  395.                                     or incomplete pathname
  396.     
  397.     __________
  398.     
  399.     Also see:    CopyErrProcPtr, FSpDirectoryCopy, FilteredDirectoryCopy,
  400.                 FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
  401. */
  402.  
  403. /*****************************************************************************/
  404.  
  405. pascal    OSErr    FSpDirectoryCopy(const FSSpec *srcSpec,
  406.                                  const FSSpec *dstSpec,
  407.                                  void *copyBufferPtr,
  408.                                  long copyBufferSize,
  409.                                  Boolean preflight,
  410.                                  CopyErrProcPtr copyErrHandler);
  411. /*    ¶ Make a copy of a directory structure in a new location.
  412.     The FSpDirectoryCopy function makes a copy of a directory structure in a
  413.     new location. If copyBufferPtr <> NIL, it points to a buffer of
  414.     copyBufferSize that is used to copy files data.  The larger the
  415.     supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then this
  416.     routine allocates a buffer in the application heap. If you pass a
  417.     copy buffer to this routine, make its size a multiple of 512
  418.     ($200) bytes for optimum performance.
  419.     
  420.     srcSpec            input:    An FSSpec record specifying the directory to copy.
  421.     dstSpec            input:    An FSSpec record specifying destination directory
  422.                             of the copy.
  423.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  424.                             is used the i/o buffer for the copy or
  425.                             nil if you want DirectoryCopy to allocate its
  426.                             own buffer in the application heap.
  427.     copyBufferSize    input:    The size of the buffer pointed to
  428.                             by copyBufferPtr.
  429.     preflight        input:    If true, FSpDirectoryCopy makes sure there are
  430.                             enough allocation blocks on the destination
  431.                             volume to hold the directory's files before
  432.                             starting the copy.
  433.     copyErrHandler    input:    A pointer to the routine you want called if an
  434.                             error condition is detected during the copy, or
  435.                             nil if you don't want to handle error conditions.
  436.                             If you don't handle error conditions, the first
  437.                             error will cause the copy to quit and
  438.                             DirectoryCopy will return the error.
  439.                             Error handling is recommended...
  440.     
  441.     Result Codes
  442.         noErr                0        No error
  443.         readErr                –19        Driver does not respond to read requests
  444.         writErr                –20        Driver does not respond to write requests
  445.         badUnitErr            –21        Driver reference number does not
  446.                                     match unit table
  447.         unitEmptyErr        –22        Driver reference number specifies a
  448.                                     nil handle in unit table
  449.         abortErr            –27        Request aborted by KillIO
  450.         notOpenErr            –28        Driver not open
  451.         dskFulErr            -34        Destination volume is full
  452.         nsvErr                -35        No such volume
  453.         ioErr                -36        I/O error
  454.         bdNamErr            -37        Bad filename
  455.         tmfoErr                -42        Too many files open
  456.         fnfErr                -43        Source file not found, or destination
  457.                                     directory does not exist
  458.         wPrErr                -44        Volume locked by hardware
  459.         fLckdErr            -45        File is locked
  460.         vLckdErr             -46        Destination volume is read-only
  461.         fBsyErr                 -47        The source or destination file could
  462.                                     not be opened with the correct access
  463.                                     modes
  464.         dupFNErr            -48        Destination file already exists
  465.         opWrErr                -49        File already open for writing
  466.         paramErr            -50        No default volume or function not
  467.                                     supported by volume
  468.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  469.         memFullErr            -108    Copy buffer could not be allocated
  470.         dirNFErr            -120    Directory not found or incomplete pathname
  471.         wrgVolTypErr        -123    Function not supported by volume
  472.         afpAccessDenied        -5000    User does not have the correct access
  473.         afpDenyConflict        -5006    The source or destination file could
  474.                                     not be opened with the correct access
  475.                                     modes
  476.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  477.                                     or incomplete pathname
  478.     
  479.     __________
  480.     
  481.     Also see:    CopyErrProcPtr, DirectoryCopy, FilteredDirectoryCopy,
  482.                 FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
  483. */
  484.  
  485. /*****************************************************************************/
  486.  
  487. #ifdef __cplusplus
  488. }
  489. #endif
  490.  
  491. #include "OptimizationEnd.h"
  492.  
  493. #endif    /* __DIRECTORYCOPY__ */
  494.